cd "C:\Users\ollfo959\Dropbox\Sexual assault\Labor market inequality and sexual harassment\Final submission\Replication files\"

use "survey_followup" , clear

*Recode education to 7 categories
replace edu=4 if edu==5 |edu==6
replace edu=5 if edu==7
replace edu=6 if edu==8
replace edu=7 if edu==9

gen woman=sex==1
gen man= sex==2

*Define dummies for seeing same-sex or opposite sex victims
gen vic = (woman==1 &  q19!=.)| (woman==0 &  q28 !=.)
gen by = (woman==0 &  q19!=.)| (woman==1 &  q28 !=.)
replace vic=. if vic!=1 & by!=1
replace by =. if vic!=1 & by!=1

*Define variable for stated harassment frequency for alternative a and b
gen freq_a= q19
replace freq_a = q28 if freq_a==.
gen freq_b= q22
replace freq_b = q31 if freq_b==.

* Code variable for type of work condition in alternative b
gen arb_b= substr(arbetsmilj_m_1_b,1,4) if q19!=.
replace arb_b= substr(arbetsmilj_k_1_b,1,4) if q28!=.
replace arb_b="non" if arb_b=="Inge"
replace arb_b="cont" if arb_b=="Anst"
replace arb_b="conf" if arb_b=="Viss"

*Define variable for harm of sexual harassment
gen harm_a= q20
replace harm_a = q29 if harm_a==.

*Define variable for labeling something as sexual harassment
gen seku_a= q21
replace seku_a = q30 if seku_a==.
gen hara_type= arbetsmilj_m_1_a if q20!=.
replace hara_type= arbetsmilj_k_1_a if q29!=.

*Generate variable for difference in harassment between harassment vignette 
*and seeing no information about work enivoronment
gen freq_treat= freq_a-freq_b if arb_b=="non"
gen freq_bn= freq_b if arb_b=="non"
gen aware =q33>=2 if q33<4

*Add data on occupation sex composition	
gen ssyk2=	ssyk12_2
joinby ssyk2 using ssyk2_shw_2015, unmatched(master)
	
*Define variable for being gender minority or majority in occupation
gen min_occ=  ssyk2_wsh>.5 if  ssyk2_wsh!=. &  wom==0
replace min_occ= 0 if  ssyk2_wsh>.5 &  ssyk2_wsh!=. &  wom==1
replace min_occ= 1 if  ssyk2_wsh<.5 &  ssyk2_wsh!=. &  wom==1
gen maj_occ=1-min_occ

*Figure A15
gen all=1
foreach samp in all woman man vic by {
	preserve
	keep if `samp'==1
	matrix freq_C =J(5,6,.)
	foreach level in 1 2 3 4 5  {	
		gen freq_a_`level' =  freq_a == `level'  if freq_a!=.
	    gen freq_b_`level' =  freq_b == `level' if  freq_b!=.
		* sexual harassment
		sum freq_a_`level' 
		matrix freq_C[`level',1]=r(mean)
		*no information
		sum freq_b_`level' if arb_b=="non"
		matrix freq_C[`level',2]=r(mean)
		gen bas = `level'
		sum bas
		matrix freq_C[`level',3]=r(mean)+0.2
		matrix freq_C[`level',4]=r(mean)-0.2
		drop bas
	}
	sum freq_a
	matrix freq_C[1,5]=r(mean)
	*no information
	sum freq_b if arb_b=="non"
	matrix freq_C[1,6]=r(mean)
	svmat freq_C
	rename freq_C1 freq_hara
	rename freq_C2 freq_no
	rename freq_C3 pos_hara
	rename freq_C4 pos_no
	rename freq_C5 m_hara
	rename freq_C6 m_no
	foreach var in  m_hara m_no{
		replace `var'=round(`var', 0.01)
	}
	gen m_xpos_hara=4.7
	gen m_xpos_no=3.8
	gen m_ypos_hara=.35
	gen m_ypos_no=.35
	
	twoway (bar freq_hara pos_hara,  fc(gs5) barw(.4)  lc(gs1) fintensity(100))  	///
		(bar freq_no pos_no, fc(gs10) barw(.4) lc(gs7) fintensity(100))  ///
		(scatter m_ypos_hara m_xpos_hara, mcolor(gs5) msymbol(square) ///
		mlabel(m_hara) mlabsize(medium) mlabcolor(gs0) mlabposition(3) mlabangle(horizontal)) ///
		(scatter m_ypos_no m_xpos_no, mcolor(gs10) msymbol(square) ///
		mlabel(m_no) mlabsize(medium) mlabcolor(gs0) mlabposition(3) mlabangle(horizontal)) ///
		, xlabel(1"1IsolatedEvent" 2 3 4 5"5ReoccuringProblem") ylabel(,angle(horizontal) grid) ///
		title(`samp', size(medlarge))  ytitle(Proportion) xtitle(Frequency of Sexual Harassment)  scheme(s1mono)  ///
		legend(order(2 "No Information" 1 "Sexual Harassment") col(2))
	graph save "`samp'_freq_main.gph", replace
	restore
}
graph combine  woman_freq_main.gph man_freq_main.gph ///
	vic_freq_main.gph by_freq_main.gph, col(2) ysize(15) xsize(20) ///
	iscale(.7) ycommon scheme(s1mono)
graph save Figure_A15, replace
	
*Table A9
log using Table_A9, replace
	sum freq_a freq_bn freq_treat harm seku 
	sum freq_a freq_bn freq_treat harm seku if vic==1
	sum freq_a freq_bn freq_treat harm seku if by==1
	sum freq_a freq_bn freq_treat harm seku if woman==1
	sum freq_a freq_bn freq_treat harm seku if man==1
	sum freq_a freq_bn freq_treat harm seku if min_occ==1	
	sum freq_a freq_bn freq_treat harm seku if maj_occ==1
	sum freq_a freq_bn freq_treat harm seku if aware==1
	sum freq_a freq_bn freq_treat harm seku if aware==0	
log close
